import { createStorage } from "./createStorage";

export function setSafeClip(text: string) {
    return setClip(text)
}

export function setSetting(setting: any) {
    const store = createStorage()
    const old = getSetting()
    store.put('setting', { ...old, ...setting })
}

export function getSetting() {
    const store = createStorage()
    return store.get('setting') || {}
}

export function formatNumber(val: number) {
    if (val < 10) return `0${val}`
    return `${val}`
}
export function formatMinute(value: number) {
    if (value <= 0) return `00:00`
    value = parseInt(`${value}`)
    const second = value % 60;
    if (value < 60 * 60) {
        const minute = Math.floor(value / 60)
        return `${formatNumber(minute)}:${formatNumber(second)}`
    } else {
        const totalMinute = Math.floor(value / 60)
        const hour = Math.floor(totalMinute / 60)
        const decMinute = totalMinute % 60;
        return `${formatNumber(hour)}:${formatNumber(decMinute)}:${formatNumber(second)}`
    }
}



export function getSystemSetting(): any {
    const storage = createStorage()
    return storage.get('SYSTEM_SETTING', {})
}
